using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Models.ServerModels
{
    public class ApiConfigModel
    {
        private string _serverAddress;
        public string UserAgent { get; set; }
        public string ApiId { get; set; }
        public string ApiToken { get; set; }
        public string Lang { get; set; }
        public string ErrorOnEmpty { get; set; }
        public string Format { get; set; }
        public string UserId { get; set; }
        public string ServerAddress {
            get
            {
                //为空时默认值
                if(string.IsNullOrEmpty(_serverAddress))
                {
                    _serverAddress = "https://dnsapi.cn/";
                }
                return _serverAddress;
            }
            set
            {
                string val = value.Substring(0,5).ToLower();
                //http变https
                if (val == "http:")
                {
                    value = "https" + value.Substring(4);
                }
                //强迫症必须判断一下
                if (value.Substring(0,5).ToLower() !="https")
                    throw new Exception("地址不正确！");
                //后面加斜线
                if (value.Substring(value.Length - 1, 1) != "/")
                    value += "/";
                _serverAddress = value;
            }
        }
    }
}
